<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */

class Admin_Form_Taxonomy{
	
	protected $_isError = false;
	protected $_messageError = null;
    protected $_data = null;
    protected $_classError = null;
    
    public function __construct($params = array(), $data = null){
        
        $translate = Zend_Registry::get('Zend_Translate');
        
        $validatorName = new Zend_Validate();
        $validatorType = new Zend_Validate();
        
        $validatorName->addValidator(new Zend_Validate_NotEmpty(), true)
                    ->addValidator(new Zend_Validate_Alnum(true), true)
                    ->addValidator(new Zend_Validate_StringLength(array('max' => 50)));
                    
        $this->_messageError['name'] = '';
        $this->_data['name'] = $params['name'];
        $this->_classError['name'] = '';
        
        if(!$validatorName->isValid($params['name'])){
            $this->_messageError['name'] = '<label class="control-label" for="inputError">' . $translate->_('category name') . current($validatorName->getMessages()) . '</label>';
            $this->_classError['name'] = 'has-error';
            $this->_isError = true;
            
            if($data != null){
                $this->_data['name'] = $data['name'];
            }else{
                $this->_data['name'] = '';
            }
        }
        
        $this->_data['type'] = $params['type'];
        
        if($data != null){
            $this->_data['id'] = $data['id'];
        }
    }
    
    public function isError(){
    	return $this->_isError;
    }
    
    public function getMessageError(){
        return $this->_messageError;
    }
    
    public function getClassError(){
        return $this->_classError;
    }
    
    public function getData(){
        return $this->_data;
    }
}